import React from 'react'
import { Row, Col, Popover, Table, Pagination, Divider } from 'antd'
import colors from '@/constants/colors'
import './table.css'
import styles from '@/components/batchRecord/table.scss'
import tableStyles from './table.scss'
import util from '@/utils'

const { Column } = Table

const SignTable = (props) => {
  const { data, pageNum, loading, pageSize, total, signStatusEnum, industryEnum, scenariosEnum, onSetDefault, onDelete, onChangePagination } = props
  const statusColor = {
    1: colors.statusPending,
    2: colors.statusPendSuc,
    3: colors.statusPendFai,
  }

  return (
    <div id="signTable">
      <Table dataSource={data} loading={loading} pagination={false} rowKey={record => record.id} scroll={{x: 1150}} >
        {/* defauls 为 1 时表示默认 */}
        <Column title="签名" dataIndex="sign" align="center" width={200} render={(value, row) => (
          <div>
            {value}
            {
              row.defauls === 1 && (<span className={tableStyles['default']}>默认</span>)
            }
          </div>
        )} />
        <Column title="行业" dataIndex="industry" align="center" width={120} render={(value) => util.getEnumDesc(industryEnum, value)} />
        <Column title="应用场景" dataIndex="application" align="center" width={120} render={(value) => util.getEnumDesc(scenariosEnum, value)} />
        <Column title="状态" dataIndex="status" align="center" width={120} render={(props,row) => (
          <span style={{color: statusColor[row.status]}} >{util.getEnumDesc(signStatusEnum, props)}</span>
        )} />
        <Column title="添加时间" dataIndex="createTime" align="center" width={120} render={(props) => util.transformTimeStampToString(props)}/>
        <Column title="审核时间" dataIndex="auditTime" align="center" width={120} render={(props) => util.transformTimeStampToString(props)}/>
        <Column title="操作" width={200} dataIndex="id9" align="center" render={(props, value, index) => (
          <span>
            {/* 有效的不是默认的显示 */}
            {(value.status === 2 && value.defauls === 0) && (
              <span>
                <a href="javascript:;" onClick={onSetDefault.bind(props, value, index)}>设为默认</a>
                <Divider type="vertical" />
              </span>
            )}
            {/* 只有不是默认的才能删除 */}
            {(value.defauls === 0) && (
              <a href="javascript:;" onClick={onDelete.bind(props, value, index)}>删除</a>
            )}
          </span>
        )} />
      </Table>
      {!!total && <div className={styles["pagination-container"]}>
        <Pagination 
          className={styles["pagination"]} showQuickJumper showTotal={(total, range) => `共${total}条`} 
          pageSize={pageSize}
          current={pageNum}
          total={total} 
          onChange={onChangePagination} 
        />
      </div>
      }
    </div>
  )
}

export default SignTable